package com.umfwechat.util;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

public class SortUtil {

	/**
	 * 集合排序
	 * @param list
	 * @return
	 */
	public static List<Map<String,String>> sortListAsc(List<Map<String,String>> list, final String propertyName){
		Collections.sort(list, new Comparator<Map<String,String>>(){
             public int compare(Map<String,String> arg0, Map<String,String> arg1) {
                 return arg0.get(propertyName).compareTo(arg1.get(propertyName));
             }
        });
		
		return list;
	}
	
	/**
	 * 集合排序(降序)
	 * @param list
	 * @return
	 */
	public static List<Map<String,String>> sortListDesc(List<Map<String,String>> list, final String propertyName){
		Collections.sort(list, new Comparator<Map<String,String>>(){
             public int compare(Map<String,String> arg0, Map<String,String> arg1) {
                 return arg1.get(propertyName).compareTo(arg0.get(propertyName));
             }
        });
		
		return list;
	}
	
}
